package fr.cyol.android.levaldesetoiles;

import android.app.AlertDialog;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;

public class RessourcesActivity extends LeValDesEtoilesActivity {
	static final Integer[] NOMS_DES_RESSOURCES = new Integer[]{
		R.string.ressource_coeur, R.string.ressource_arme,
		R.string.ressource_esprit, R.string.ressource_pouvoir, 
	};

	static final Integer[] IMAGES_DES_RESSOURCES = {
	        R.drawable.coeur, R.drawable.arme,
	        R.drawable.esprit, R.drawable.pouvoir, 
	};

	static final Integer[] IMAGES_DES_RESSOURCES_B = {
	        R.drawable.coeur_b, R.drawable.arme_b,
	        R.drawable.esprit_b, R.drawable.pouvoir_b, 
	};
	

	static final Integer[] DESCRIPTION_DES_RESSOURCES = new Integer[]{
		R.string.description_ressource_coeur, R.string.description_ressource_arme,
		R.string.description_ressource_esprit, R.string.description_ressource_pouvoir, 
	};
	static final Integer[] NOMS_DES_FIGURES = new Integer[]{
		R.string.figure_valet, R.string.figure_dame,
		R.string.figure_roi, R.string.figure_joker, 
	};

	static final Integer[] IMAGES_DES_FIGURES = {
	        R.drawable.v, R.drawable.d,
	        R.drawable.r, R.drawable.j, 
	};

	static final Integer[] IMAGES_DES_FIGURES_B = {
	        R.drawable.v_b, R.drawable.d_b,
	        R.drawable.r_b, R.drawable.j_b, 
	};

	static final Integer[] DESCRIPTION_DES_FIGURES = new Integer[]{
		R.string.description_figure_valet, R.string.description_figure_dame,
		R.string.description_figure_roi, R.string.description_figure_joker, 
	};
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lvde_ressources);
        
        //Gestion de l'affichage du Grid
        GridView gridviewRessources = (GridView) findViewById(R.id.gridview_ressources);
        gridviewRessources.setAdapter(new ImageAdapter(this, NOMS_DES_RESSOURCES, IMAGES_DES_RESSOURCES));

        gridviewRessources.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                detailRessource(v, position);
            }
        });
        GridView gridviewFigures = (GridView) findViewById(R.id.gridview_figure);
        gridviewFigures.setAdapter(new ImageAdapter(this, NOMS_DES_FIGURES, IMAGES_DES_FIGURES));

        gridviewFigures.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                detailFigure(v, position);
            }
        });
       
    }
    //Appel du Dialog
    public void detailRessource(View vue, int position){
        Resources res = getResources();
    	AlertDialog.Builder dialogRessource = new AlertDialog.Builder(this);
    	dialogRessource.setTitle(res.getText(NOMS_DES_RESSOURCES[position]));
    	dialogRessource.setIcon(IMAGES_DES_RESSOURCES_B[position]);
    	dialogRessource.setMessage(res.getText(DESCRIPTION_DES_RESSOURCES[position]));
    	
    	dialogRessource.setNegativeButton(res.getText(R.string.fermer), null);
    	dialogRessource.show();
    }
    //Appel du Dialog
    public void detailFigure(View vue, int position){
        Resources res = getResources();
    	AlertDialog.Builder dialogFigure = new AlertDialog.Builder(this);
    	dialogFigure.setIcon(IMAGES_DES_FIGURES_B[position]);
    	dialogFigure.setTitle(res.getText(NOMS_DES_FIGURES[position]));
    	dialogFigure.setMessage(res.getText(DESCRIPTION_DES_FIGURES[position]));
    	
    	dialogFigure.setNegativeButton(res.getText(R.string.fermer), null);
    	dialogFigure.show();
    }
}

